#!/usr/bin/env python3
# _*_coding:utf-8 _*_
__author__ = "Gao"
from django import template
from django.utils.safestring import mark_safe

register = template.Library()

@register.simple_tag
def filter_all(args, k):
    '''全选'''
    res_str = ''
    if k == 'article_type':
        if args['article_type'] == 0:
            res_str = '<a class="active" href="/backend/article-0-%s.html">全部</a>' %args['category_id']
        else:
            res_str = '<a href="/backend/article-0-%s.html">全部</a>'%args['category_id']
    elif k == 'category':
        if args['category_id'] == 0:
            res_str = '<a class="active" href="/backend/article-%s-0.html">全部</a>'%args['article_type']
        else:
            res_str = '<a href="/backend/article-%s-0.html">全部</a>'%args['article_type']

    return mark_safe(res_str)


@register.simple_tag
def filter_one(query_res,args,k):
    '''选择单一项'''
    res_str = []
    if k == 'article_type':
        for row in query_res:
            if row[0] == args['article_type']:
                temp = '<a class="active" href="/backend/article-%s-%s.html">%s</a>'%(row[0],args['category_id'],row[1])
            else:
                temp = '<a href="/backend/article-%s-%s.html">%s</a>'%(row[0],args['category_id'],row[1])
            res_str.append(temp)
    elif k == 'category':
        for row in query_res:
            if row.nid == args['category_id']:
                temp = '<a class="active" href="/backend/article-%s-%s.html">%s</a>'%(args['article_type'],row.nid,row.title)
            else:
                temp = '<a href="/backend/article-%s-%s.html">%s</a>'%(args['article_type'],row.nid,row.title)
            res_str.append(temp)
    return mark_safe(''.join(res_str))